package com.hjt.gulimall.search.controller;

import com.hjt.gulimall.search.service.MallSearchService;
import com.hjt.gulimall.search.vo.SearchParam;
import com.hjt.gulimall.search.vo.SearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * @author:97007
 * @date:2021/9/24 16:21
 */
@Controller
public class SearchController {


    @Autowired
    MallSearchService searchService;


    /**
     * 商品检索接口
     * @param searchParam 检索参数
     */
    @GetMapping("/list.html")
    public String list(SearchParam searchParam, Model model, HttpServletRequest request) {
        // 根据页面查询参数，去Es中检索商品
        searchParam.set_queryString(request.getQueryString());
        SearchResult result = searchService.search(searchParam);
        model.addAttribute("result", result);
        return "list";
    }

}
